<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>电子文档查询列表</title>
</head>
<body>
    <h1>电子文档列表</h1>

    <form action="/edocEntry/page" th:action="@{/edocEntry/page}" method="post">
        <input type="hidden" name="current" th:value="${pageInfo.current}" />
        <input type="hidden" name="pages" th:value="${pageInfo.pages}">
        <div>
            <label for="categoryId">文档分类:</label>
            <select id="categoryId" name="categoryId">
                <option value="">全部</option>
                <option th:each="l:${list}" th:value="${l.id}" th:text="${l.name}" th:selected="${l.id==entry.categoryId}"></option>
            </select>
            <button type="submit" id="search-btn" >查询</button>
            <button type="button" id="reset-btn">重置</button>
            <button style="margin-left: 290px"><a href="/edocEntry/save" th:href="@{/edocEntry/save}">添加电子文档</a></button>
        </div>
    </form>
    <table border="1">
        <tr>
            <th>文档编号</th>
            <th>文档名称</th>
            <th>文档摘要</th>
            <th>上传人</th>
            <th>上传时间</th>
            <th colspan="3">操作</th>
        </tr>
        <tr th:each="l:${pageInfo.records}">
            <td th:text="${l.id}"></td>
            <td th:text="${l.title}"></td>
            <td th:text="${l.summary}"></td>
            <td th:text="${l.uploaduser}"></td>
            <td th:text="${#dates.format(l.createdate,'yyyy-MM-dd')}"></td>
            <td><a href="#" th:onclick="|view(${l.id})|">查看</a></td>
            <td><a href="#" th:onclick="|edit(${l.id})|">修改</a></td>
            <td><a href="#" th:onclick="|del(${l.id})|">删除</a></td>
        </tr>
    </table>
    <div>
        <a th:if="${pageInfo.current>1}" href="/edocEntry/page" th:href="@{/edocEntry/page(pageNo=1)}">首页</a>
        <a th:if="${pageInfo.current>1}" href="/edocEntry/page" th:href="@{/edocEntry/page(pageNo=${pageInfo.current}-1)}">上一页</a>
        <a th:if="${pageInfo.current<pageInfo.pages}" href="/edocEntry/page" th:href="@{/edocEntry/page(pageNo=${pageInfo.current}+1)}">下一页</a>
        <a th:if="${pageInfo.current<pageInfo.pages}" href="/edocEntry/page" th:href="@{/edocEntry/page(pageNo=${pageInfo.pages})}">尾页</a>
        <span th:text="|第${pageInfo.current}页/共${pageInfo.pages}页|"></span>
    </div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    /** 删除信息 */
    function del(id){
        if(confirm("确认要删除吗？")){
            $.ajax({
                // 使用Restful风格
                url: "/edocEntry/del/" + id,
                type: "DELETE",
                dataType: "json",
                success: function(data){
                    if(data.code == 200){
                        // 正常状态
                        alert("删除成功")
                        // 重新加载数据
                        location.reload();
                    }else{
                        alert("数据删除失败，请重试！");
                    }
                }
            })
        }
    }

    /** 修改信息  */
    function edit(id){
        // 跳转修改路径
        window.location.href = "/edocEntry/edit?id=" + id;
    }
    /** 查看信息  */
    function view(id){
        // 跳转查看路径
        window.location.href = "/edocEntry/view/" + id;
    }
</script>
<style>
    table{
        text-align: center;
    }
</style>
